package com.jn.util.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.jn.util.CodeUtil;

public class DictCodeLabelTag extends BodyTagSupport {

	private static final long serialVersionUID = -4450256677611743965L;
	private String codeType;
	private String codeValue;

	@Override
	public int doStartTag() throws JspException {
		if (codeType == null)
			throw new JspException("codeType不能为空");
		if (codeValue == null)
			return 0;
		String codeName = CodeUtil.getName(codeType, codeValue);
		if (codeName == null)
			codeName = "";
		try {
			this.pageContext.getOut().print(codeName);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SKIP_PAGE;
	}

	@Override
	public void release() {
		super.release();
		this.codeType = null;
		this.codeValue = null;
	}

	public String getCodeType() {
		return codeType;
	}

	public void setCodeType(String codeType) {
		this.codeType = codeType;
	}

	public String getCodeValue() {
		return codeValue;
	}

	public void setCodeValue(String codeValue) {
		this.codeValue = codeValue;
	}

}
